package top.heue.test.activity.flash

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import kotlinx.coroutines.delay
import top.heue.test.fragment.main.MainFragment
import top.heue.utils.FC
import top.heue.utils.base.util.system.SystemUtil
import top.heue.utils.lifecycle.base.BaseModel
import top.heue.utils.lifecycle.helper.onMain

class FlashModel : BaseModel() {
    fun init(activity: FlashActivity) {
        SystemUtil.hideBar(activity)
        activity.lifecycle.addObserver(object : LifecycleEventObserver {
            override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
                if (event == Lifecycle.Event.ON_RESUME) {
                    go(activity)
                }
            }
        })
    }

    fun go(activity: FlashActivity) {
        onMain {
            FC.startFragment(activity, MainFragment::class.java) {
                isFit = true
            }
            activity.finishAfterTransition()
        }
    }
}